'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:ContractZjcontractCtrl
 * @description
 * # ContractZjcontractCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('ContractZjcontractCtrl', function($scope, $filter, $rootScope, openApi, $http, Util, $routeParams, FormSubmit) {
        $scope.param = {};
        // --------------------------------------
        var payWayList = [{
            key: "一次性付清",
            value: "一次性付清"
        }, {
            key: "每年支付",
            value: "每年支付"
        }, {
            key: "每月支付",
            value: "每月支付"
        }, {
            key: "其他方式",
            value: "其他方式"
        }];

        $scope.sheetObj = {};
        // 底部关联模块类型选框添加
        var majorTypeObj = {},
            selectData, params;
        majorTypeObj.sheettitle = "证件类别";
        majorTypeObj.callback = function(item) {
            $scope.param.major = item.selectTab
            $scope.param.majorContent = item.selectTabContent
        }
        $scope.sheetObj.majorTypeObj = majorTypeObj;
        $scope.showMajorTypeObj = function() {
            var param = {};
            param.type = "证件类别";
            Util.getKeyValue(param, function(data) {
                $scope.sheetObj.majorTypeObj.tabList = data.data
                $scope.showSheet("majorTypeObj")
            })

        };
        $scope.showSheet = function(type) {
            var sheetObj = $scope.sheetObj[type]
            $scope.sheetObj.type = type
            $scope.sheetObj.tabList = sheetObj.tabList
            $scope.sheetObj.sheettitle = sheetObj.sheettitle
            $scope.sheetObj.ifshowSheet = true
            $rootScope.showMasker = true
        };
        //------------------------------关联模块
        // 底部款项类型选框添加
        var payWayObj = {};
        payWayObj.sheettitle = "付款方式";
        payWayObj.tabList = payWayList;
        payWayObj.callback = function(item) {
            $scope.param.payWay = item.selectTab
            $scope.param.payWayContent = item.selectTabContent
        }
        $scope.sheetObj.payWayObj = payWayObj;
        $scope.submit = function() {
            if (!$scope.param.major) {
                Util.Toast("请选择证件类型");
                return;
            }
            if (!$scope.param.constructor_) {
                Util.Toast("请填写证件姓名");
                return;
            }
            if (!$scope.param.specialty) {
                Util.Toast("请填写专业");
                return;
            }
            if (!$scope.param.cost) {
                Util.Toast("请填写证件费用");
                return;
            }
            if (!$scope.param.payWay) {
                Util.Toast("请选择付款方式");
                return;
            }
            if (!$scope.param.filePath) {
                Util.Toast("请选择附件");
                return;
            }
            // 提交
            var urlParam = "?operationId=-2" + "&&processId=" + $routeParams.id + "&&url=" + openApi.agreementApply
            var options = {};
            options.urlParam = urlParam;
            options.param = $scope.param
            var TVtype;
            TVtype = Util.getTVType(); //根据页面的来源来判断是发起的流程还是修改的流程，如果是发起的则不管，如果是修改的则获取数据用来回显
            // 如果是修改页面的话则提交的地址不一样，参数一样
            if (TVtype == Util.UPDATE) {
                options.url = openApi.ip + openApi.agreementApply
            }
            new FormSubmit(options);
        };
        var init = function() {
            // 获取回显的详细信息
            Util.getDetailData($routeParams.id, function(data) {
                $scope.param = data;
            });
            // 显示审批记录判断
            Util.showloglist($routeParams.id, function(data) {
                $scope.logData = data;
            });
        };
        // 初始化
        init();

    });
